package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanhua.dubbo.mapper.UserMapper;
import com.tanhua.model.domain.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class UserApiImpl implements UserApi{

    @Autowired
    private UserMapper userMapper;

    /**
     * 获取用户信息
     * @param mobile
     * @return
     */
    @Override
    public User findByMobile(String mobile) {
        return userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getMobile,mobile));
    }

    /**
     * 新增用户信息,并获取用户id
     * @param user
     * @return
     */
    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    /**
     * 修改手机号-保存
     *
     *
     */
    @Override
    public void updateNewPhone(User user) {
        userMapper.updateById(user);
    }

    /**
     * 修改信息
     *
     * @param user
     */
    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    /**
     * 根据当前用户id查询
     *
     * @param userId
     * @return
     */
    @Override
    public User findById(Long userId) {
        return userMapper.selectById(userId);
    }

    /**
     * 根据环信id查询用户详情信息
     *
     * @param huanxinId
     * @return
     */
    @Override
    public User findByHuanxin(String huanxinId) {
        return userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getHxUser,huanxinId));
    }

    /**
     * 查询所有用户信息
     *
     * @return
     */
    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }
}
